<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<link rel="stylesheet" href="<c:url value='/resource/css/bootstrap.css'/>">
<link rel="stylesheet" href="<c:url value='/resource/css/darktooltip.css'/>">
<link rel="stylesheet" href="<c:url value='/resource/css/animate.min.css'/>">
<link rel="stylesheet" href="<c:url value='/resource/css/style.css'/>">
<script src="<c:url value='/resource/js/jquery-1.9.1.min.js'/>"></script>
<script src="<c:url value='/resource/js/lib/bootstrap.min.js'/>"></script>
<link rel="stylesheet" href="<c:url value='/resource/css/common.css'/>">
<script src="<c:url value='/resource/js/common.js'/>"></script>
<script src="<c:url value='/resource/js/rsa/Barrett.js'/>"></script>
<script src="<c:url value='/resource/js/rsa/BigInt.js'/>"></script>
<script src="<c:url value='/resource/js/rsa/RSA.js'/>"></script>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>扫码登录</title>
    <style>
        .appLogin { width: 320px; margin: 0 auto;}
        .al-logo { width: 200px; height: 60px; background: url(<c:url value="/resource/images/register-logo.png"/>) no-repeat; margin: 20px auto 40px auto;}
        .al-item { padding: 0 15px;}
        .al-item ul {display:block; margin-bottom: 30px;}
        .al-item li { margin-bottom: 15px;}
        .al-item li input { height: 44px; line-height: 44px; width: 100%; border: #eee solid 1px; padding: 0 15px; border-radius: 4px;}
        .al-item .btn { padding: 11px 12px;}
    </style>
</head>
<body>
<div class="appLogin">

    <div class="al-logo"></div>

    <div class="al-item">
        <c:if test="${current_member==null}">
         <div id="to_login">
        <input type="hidden" id="uuid" value="${uuid}">
        <ul>
            <li>
                <input type="text" id="accountId" placeholder="帐号">
            </li>
            <li>
                <input type="password" id="password" placeholder="密码">
            </li>
        </ul>
        <div class="btn-box">
            <button class="btn btn-blue btn-block" id="login">登录</button>
        </div>
         </div>
            <div id="confirm_login" style="display:none;">
            <button class="btn btn-blue btn-block" name="confirm">确认登录</button>
        <button class="btn btn-blue btn-block" name="cancle">取消</button>
            </div>
        </c:if>
        <c:if test="${current_member!=null}">
            <button class="btn btn-blue btn-block" name="confirm">确认登录</button>
            <button class="btn btn-blue btn-block" name="cancle">取消</button>
        </c:if>
    </div>
</div>
</body>
</html>
<script>
    $(function(){
       $("#login").click(function(){
           $.ajax({
               type: 'POST',
               url: "<c:url value='/members/scan_login'/>",
               data:{
                   accountId:$('#accountId').val(),
                   password:getEncrypted($('#password').val()),
                   uuid:$('#uuid').val()
               },
               success: function(res){
                   if(!res.succ){
                       toast(res.msg);
                   }else{
                       toast("登录成功");
                       $("#to_login").hide();
                       $("#confirm_login").show();
                   }
               },
               error:function(res){
                   toast(res.msg);
               }
           });
       });
        $("button[name='confirm']").click(function(){
            $.ajax({
                type: 'POST',
                url: "<c:url value='/members/confirm_login?uuid=${uuid}'/>",
                success: function(res){
                    if(res.succ){
                        toast("已确认登录");
                        window.history.back();
                        if(WeixinJSBridge){
                            WeixinJSBridge.call('closeWindow');
                        }
                    }else{
                        toast(res.msg);
                    }
                },
                error:function(res){
                    toast(res.msg);
                }
            });

        });
        $("button[name='cancle']").click(function(){
            window.history.back();
            if(WeixinJSBridge){
                WeixinJSBridge.call('closeWindow');
            }
        });
    });
    function getEncrypted(data) {
        setMaxDigits(130); //1024位就是130，2048位就是260.。。。。。。
        var key1 = new RSAKeyPair("${e}","","${n}");	//从服务端获取到的n和e可以得出公钥
        var encode_content = encodeURIComponent(data);
        var encryptData = encryptedString(key1,encode_content);
        return encryptData;
    }
</script>
